<template>
  <!-- 搜索歌单 -->
  <div id="seachSongSheet">
    <van-list
      v-model="loading"
      :finished="finished"
      offset="10"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell-group>
        <van-cell
          v-for="(sheet, index) in songSheetList"
          :key="index"
          :title="sheet.name"
          @click="handleOpen(sheet.id)"
        >
          <template #label>
            <span>{{ `${sheet.trackCount}首音乐 ` + " " }}</span>
            <span>{{ ` by ${sheet.creator.nickname}` + " " }} </span>
            <span> 播放{{ sheet.playCount | playCount }}</span>
          </template>
          <template #icon>
            <van-image
              style="margin-right: 0.3rem"
              center
              width="46"
              height="46"
              :src="sheet.coverImgUrl"
            />
          </template>
        </van-cell>
      </van-cell-group>
    </van-list>
  </div>
</template>

<script>
import { getSearch } from "@/api/search";
export default {
  name: "seachSongSheet",
  data() {
    return {
      songSheetList: [],
      loading: true,
      finished: false,
      rowText: "",
      limit: 10,
      type: 1000,
    };
  },
  filters: {
    playCount(val) {
      if (val / 10000 > 1) {
        return (val / 10000).toFixed(1) + "万次";
      }
      return val + "次";
    },
  },
  methods: {
    handleOpen(id) {
      this.$router.push({
        path: `/songSheet`,
        query: { id },
      });
    },
    onLoad() {
      this.loading = true;
      this.limit = this.limit + 10;
      getSearch(this.rowText, this.limit, this.type).then((res) => {
        if (res.code == 400) {
          return this.finished = true;
        }
        this.songSheetList = res.result.playlists;
        this.loading = false;
      });
    },
    initData(row, limit, type) {
      getSearch(this.rowText, limit, type).then((res) => {
        this.songSheetList = res.result.playlists;
        this.loading = false;
      });
    },
  },
};
</script>

<style scoped>
#seachSongSheet /deep/ .van-image__img {
  border-radius: 0.11rem;
}
</style>